<?php
/**
* Template scaffolding.
*/
class [[CLASS_NAME]] extends ScribbleTemplate implements IScribbleTemplate {

	/**
	* @param Buan\Model Content model
	* @param array Data to gather (consider it to be $_POST)
	* @return mixed
	*/
	public function gatherPopulatorData(PageModel $page, $data=array()) {

		// Build an object from $data that is suitable for use in the content model
		// used by this template
		$data = isset($_POST['[[POST_ARRAY_INDEX]]']) ? $_POST['[[POST_ARRAY_INDEX]]'] : array();
		$obj = new StdClass();
		foreach($data as $k=>$v) {
			$obj->{$k} = $v;
		}

		// Return the object
		return $obj;
	}

	/**
	* @return Buan\IViewEngine
	*/
	private function generateViewEngine() {
		return call_user_func([[VIEW_ENGINE_GENERATOR]]);
	}

	/**
	* @param PageContentModel Content model
	* @return ScribblePublicView
	*/
	public function getFrontEndView(PageContentModel $content) {

		// Generate the View
		$view = new ScribblePublicView($this->generateViewEngine());
		$view->setSource(dirname(__FILE__).'/front-end.tpl');

		// Populate the View with data from the $page

		// Result
		return $view;
	}

	/**
	* @return string
	*/
	public function getLongDescription() {
		return "[[LONG_DESCRIPTION]]";
	}

	/**
	* @param PageContentModel Content model
	* @return ScribbleAdminView
	*/
	public function getPopulatorView(PageContentModel $content) {
		$view = new ScribbleAdminView($this->generateViewEngine());
		$view->setSource(dirname(__FILE__).'/populator.tpl');
		$view->content = $content;
		$view->page = $content->findRelatives('Page')->get(0);
		return $view;
	}

	/**
	* @return string
	*/
	public function getShortDescription() {
		return "[[SHORT_DESCRIPTION]]";
	}

	/**
	* @return string
	*/
	public function getTitle() {
		return "[[TITLE]]";
	}

	/**
	* @return int
	*/
	public function getType() {
		return self::TYPE_[[TYPE]];
	}

	/**
	* @param PageModel Page whose content will be validated
	* @param array Any error messages will be added to this array
	* @return bool
	*/
	public function validatePageContent(PageModel $page, &$messages) {
		return TRUE;
	}
}
?>